/**
 * @flow
 */

import React from 'react';
import {
  AppRegistry
  , TouchableHighlight,
  TouchableNativeFeedback,
  Text,
  StyleSheet,
  ScrollView,

} from 'react-native';
import App from './src/index'

let index = 5;

import { GiftedChat } from 'react-native-gifted-chat';
import MessageInputPanel from './src/core/component-biz/comp.message-input-panel2.js';



class Example extends React.Component {

  state = {
    messages: [],
  };

  componentWillMount() {
    this.setState({
      messages: [
        {
          _id: 1,
          text: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
          createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
          user: {
            _id: 1,
            name: 'React Native',
            avatar: 'http://106.3.143.248/media/237.jpg',
          },
          image: 'http://106.3.143.248/media/237.jpg',
        },
        {
          _id: 2,
          text: '这是个系统消息',
          createdAt: new Date(Date.UTC(2016, 5, 11, 17, 21, 0)),
          system: true,
          // Any additional custom parameters are passed through
        }
      ],
    });
  }

  onSend(messages = []) {
    this.setState((previousState) => ({
      messages: GiftedChat.append(previousState.messages, messages),
    }));
  }


  onLoadEarlier() {

    index = index + 2;
    let messages = [
      {
        _id: index + 1,
        text: '历史消息' + (index + 1),
        createdAt: new Date(Date.UTC(2016, 5, 11, 17, 19, 0)),
        user: {
          _id: 3,
          name: 'React Native',
          avatar: 'http://106.3.143.248/media/237.jpg',
        },
      },
      {
        _id: index + 2,
        text: '历史消息' + (index + 2),
        createdAt: new Date(Date.UTC(2016, 5, 11, 17, 18, 0)),
        user: {
          _id: 4,
          name: 'React Native',
          avatar: 'http://106.3.143.248/media/237.jpg',
        },
      },

    ];


    this.setState((previousState) => ({
      messages: GiftedChat.prepend(previousState.messages, messages),
    }));

  }

  /**点击人员头像.*/
  onPressAvatar() {

  }

  renderInputToolbar() {

    return <MessageInputPanel />;


  }



  render() {
    return (
        <GiftedChat
          messages={this.state.messages}
          placeholder={'请输入消息'}
          loadEarlier={true}
          onLoadEarlier={this.onLoadEarlier.bind(this)}
          isLoadingEarlier={false}
          label={'查看更多'}
          timeFormat={'HH:mm'}
          dateFormat={'YYYY-MM-DD'}
          onSend={(messages) => this.onSend(messages)}
          onPressAvatar={this.onPressAvatar}
          primaryStyle={styles.primaryStyle}
          user={{
            _id: 1,
            name: 'React Native',
            avatar: 'http://106.3.143.248/media/237.jpg',
          }}
        />
      
    );
  }

}

AppRegistry.registerComponent('shequnsiweiapp', () => App);


const styles = StyleSheet.create({
  container: {
    flex: 1,

  },
  primaryStyle: {
    backgroundColor: "#F5F5F7",
  },
  containerStyle:{
  }
});
